package org.krivtsun.jpref;

import java.awt.*;
import java.awt.image.BufferedImage;
import java.util.*;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: kontiky
 * Date: 25.03.2007
 * Time: 0:17:02
 * To change this template use File | Settings | File Templates.
 */
public class ComputerGamer extends Gamer {

    private final Set<Card> cardSet = new TreeSet<Card>();

    ComputerGamer() {
        int width = BORDER + ImageProvider.getCardWidth() / 4 * 9 + ImageProvider.getCardWidth() + BORDER;
        Dimension dim = new Dimension(width, BORDER + ImageProvider.getCardHeight() + BORDER);
        setMinimumSize(dim);
        setPreferredSize(dim);
    }

    public void addCard(Card card) {
        cardSet.add(card);
    }

    protected BufferedImage getCardImage(Card card) {
        return ImageProvider.getBackImage(0);
        //return ImageProvider.getCardImage(card);
    }

    protected void paintComponent(Graphics g) {
        super.paintComponent(g);

        int x = BORDER;
        List<Card> cardList = new ArrayList<Card>(cardSet);
        Collections.sort(cardList, new Comparator<Card>() {
            public int compare(Card o1, Card o2) {
                int result = o1.getSuit().compareTo(o2.getSuit());
                if (result == 0) {
                    result = -o1.getRank().compareTo(o2.getRank());
                }
                return result;
            }
        });
        for (Card c : cardList) {
            drawCard(getCardImage(c), g, x, BORDER);
            x += ImageProvider.getCardWidth() / 4;
        }
    }

}
